#include "OceanMaya.h"

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#include "max.h"
#include "resource.h"

#include "simpmod.h"
#include "simpobj.h"
#include "iparamm2.h"

#define HOT_CID Class_ID(0x30928ee2, 0x719e8ae6)

TCHAR *GetString(int id)
{
	static TCHAR buf[256];

	if (hInstance)
		return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL;

	return NULL;
}

class HotMod : public SimpleMod2
{	
	public:

	HotMod();
	
	int version;

	void DeleteThis() { delete this; }
	void GetClassName(TSTR& s) { s= GetString(IDS_RB_HOT_OSM_CLASS); }  
	virtual Class_ID ClassID() { return HOT_CID;}
	void BeginEditParams( IObjParam  *ip, ULONG flags,Animatable *prev);
	void EndEditParams( IObjParam *ip,ULONG flags,Animatable *next);
	int	NumParamBlocks() { return 1; }	
	IParamBlock2* GetParamBlock(int i) { return pblock2; }
	IParamBlock2* GetParamBlockByID(BlockID id) { return (pblock2->ID() == id) ? pblock2 : NULL; }
	IOResult Load(ILoad *iload);
	RefTargetHandle Clone(RemapDir& remap = DefaultRemapDir());
	TCHAR *GetObjectName() { return GetString(IDS_RB_HOT);}
	Deformer& GetDeformer(TimeValue t,ModContext &mc,Matrix3& mat,Matrix3& invmat);		
	Interval GetValidity(TimeValue t);
	void InvalidateUI();

	bool rebuild;

	// Ocean.h stuff
	protected:
		drw::Ocean *ocean;
		drw::OceanContext *oceanContext;
		float oceanScale;

};


class HotDeformer: public Deformer
{
	public:
		Matrix3 transform, invtransform;

		Box3 bbox;
		TimeValue time;
		bool interpolation;
		bool rebuild;

		HotDeformer();
		HotDeformer(Matrix3& tm, Matrix3& itm, drw::Ocean* _o, drw::OceanContext* _oc);

		Point3 Map(int i, Point3 p);

		// Ocean.h stuff
		protected:
			drw::Ocean* ocean;
			drw::OceanContext* oceanContext;
			//drw::EvalData* evaldata;

};

class HotClassDesc:public ClassDesc2
{
	public:
	int IsPublic() { return 1; }
	void *Create(BOOL loading = FALSE) { return new HotMod; }
	const TCHAR *ClassName() { return GetString(IDS_RB_HOT_OSM_CLASS); }
	SClass_ID SuperClassID() { return OSM_CLASS_ID; }
	Class_ID ClassID() { return HOT_CID; }
	const TCHAR *Category() { return GetString(IDS_RB_HOTMOD);}
	const TCHAR *InternalName()	{return _T("HotMod");}
	HINSTANCE HInstance() {return hInstance;};
};

static HotClassDesc hotDesc;

ClassDesc* GetHotModDesc()
{
	return &hotDesc;
}

class HotDlgProc : public ParamMap2UserDlgProc
{
	public:
	INT_PTR DlgProc(TimeValue t,IParamMap2* map,HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
	void DeleteThis() {}
};

static HotDlgProc theHotProc;
